package com.atguigu.srb.core.controller.admin;

import com.atguigu.srb.core.pojo.entity.UserLoginRecord;
import com.atguigu.srb.core.result.R;
import com.atguigu.srb.core.service.UserLoginRecordService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//@CrossOrigin
@RestController
@Api(tags = "会员登录日志")
@RequestMapping("/admin/core/userLoginRecord")
public class AdminUserLoginRecordController {
    @Autowired
    private UserLoginRecordService userLoginRecordService;

    @ApiOperation(value = "获取会员登录日志")
    @GetMapping("/list/{userId}")
    public Object getRecord(@PathVariable("userId") @ApiParam(value = "会员id", required = true) Long userId) {

        QueryWrapper<UserLoginRecord> queryWrapper = new QueryWrapper<>();

        queryWrapper.eq("user_id", userId);

        List<UserLoginRecord> list = userLoginRecordService.list(queryWrapper);

        if (ObjectUtils.isEmpty(list)) {
            return R.error().message("没有查到数据");
        }

        return R.ok().data("list", list);
    }

}
